package com.woniu.service.impl;

import com.woniu.entity.TakeawayOrder;
import com.woniu.mapper.TakeawayMapper;
import com.woniu.service.TakeawayService;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class TakeawayServiceImpl implements TakeawayService {
    private TakeawayMapper takeawayMapper;
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public List<TakeawayOrder> queryAll() {
        List<TakeawayOrder> takeawayOrders = takeawayMapper.queryAll();
//        List<String> takeawayAll = takeawayOrders.stream()
//                .map(e -> e.getDeliveryId()+"")
//                .collect(Collectors.toList());
        for (TakeawayOrder takeawayOrder : takeawayOrders) {
            redisTemplate.opsForHash().put("TakeawayAll",takeawayOrder.getDeliveryId()+"",takeawayOrder);
        }
        return takeawayOrders;
    }

    @Override
    public List<TakeawayOrder> queryTakeOrderBy(TakeawayOrder takeawayOrder) {
        return takeawayMapper.queryAllBy(takeawayOrder);
    }
}
